package ex.datastream.functions.richFunction;


import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;

import java.util.UUID;

/**
 * 多并行度数据源
 */
public  class RichParallelSourceFunc extends RichParallelSourceFunction<String> {
    private boolean flag = true;

    @Override
    public void run(SourceContext<String> sourceContext) throws Exception {
        while (flag) {
            sourceContext.collect(UUID.randomUUID().toString());
            System.out.println("SubTask:" + getRuntimeContext().getIndexOfThisSubtask() + " run MySource!");
            Thread.sleep(200000);
        }
    }

    @Override
    public void cancel() {
        flag = false;
        System.out.println("SubTask:" + getRuntimeContext().getIndexOfThisSubtask() + "cancel MySource3");
    }
}
